import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import qiankun from "vite-plugin-qiankun";
import { configBundleSpiderPlugin } from "./build/bundleSpider";

const isBuild = process.env.NODE_ENV === "production";
// https://vitejs.dev/config/
export default defineConfig({
  base: "/cy-jeecg-ui/",
  plugins: [
    vue(),
    vueJsx(),
    qiankun("cy-jeecg-ui", {
      // 第一个参数 qiankunName 测试了可以任意，不用跟 package.json name 一致
      useDevMode: true,
    }),
    configBundleSpiderPlugin(isBuild),
  ],
  server: {
    host: true,
    port: 5173,
    cors: true, // 主应用获取子应用时跨域响应头
  },
  preview: {
    host: true,
    port: 5173,
    cors: true, // 主应用获取子应用时跨域响应头
  },
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
